home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / scan.sh < prev    next >
Text File  |  1998-07-17  |  2KB  |  61 lines

  1. #!/usr/local/bin/perl -s
  2. #
  3. #   Scan a subnet for valid hosts; if given hostname, will look at the
  4. # 255 possible hosts on that net.  Report if host is running rexd or
  5. # ypserv.
  6. #
  7. #  Usage:  scan n.n.n.n
  8.  
  9. # mine, by default
  10. $default = "130.80.26";
  11.  
  12. $| = 1;
  13.  
  14. if ($v) { $verbose = 1; }
  15.  
  16. if ($#ARGV == -1) { $root = $default; }
  17. else { $root = $ARGV[0]; }
  18.  
  19. # ip address
  20. if ($root !~ /[0-9]+\.[0-9]+\.[0-9]+/) {
  21.         ($na, $ad, $ty, $le, @host_ip) = gethostbyname($root);
  22.         ($one,$two,$three,$four) = unpack('C4',$host_ip[0]);
  23.         $root = "$one.$two.$three";
  24.         if ($root eq "..") { die "Can't figure out what to scan...\n"; }
  25.         }
  26.  
  27. print "Subnet $root:\n" if $verbose;
  28. for $i (01..255) {
  29.         print "Trying $root.$i\t=> " if $verbose;
  30.         &resolve("$root.$i");
  31.         }
  32.  
  33. #
  34. #  Do the work
  35. #
  36. sub resolve {
  37.  
  38. local($name) = @_;
  39.  
  40. # ip address
  41. if ($name =~ /[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+/) {
  42.         ($a,$b,$c,$d) = split(/\./, $name);
  43.         @ip = ($a,$b,$c,$d);
  44.         ($name) = gethostbyaddr(pack("C4", @ip), &AF_INET);
  45.         }
  46. else {
  47.         ($name, $aliases, $type, $len, @ip) = gethostbyname($name);
  48.         ($a,$b,$c,$d) = unpack('C4',$ip[0]);
  49.         }
  50.  
  51. if ($name && @ip) {
  52.         print "$a.$b.$c.$d\t$name\n";
  53.         system("if ping $name 5 > /dev/null ; then\nif rpcinfo -u $name 100005 > /dev/null ; then showmount -e $name\nfi\nif rpcinfo -t $name 100017 > /dev/null ; then echo \"Running rexd.\"\nfi\nif rpcinfo -u $name 100004 > /dev/null ; then echo \"R
  54. unning ypserv.\"\nfi\nfi");
  55.         }
  56. else { print "unable to resolve address\n" if $verbose; }
  57.  
  58. }
  59.  
  60. sub AF_INET {2;}
  61.